﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KeywordAuction;
using Simulation.Mechanism;

namespace Simulation.Factory
{
    public class AuctionFactoryForChapter5WithGSP : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var auctionHost = new AuctionHost();
            auctionHost.Name = "Chap5.ExtendStrategyWithGSP";
            auctionHost.AuctionMechanism = new GSPAuctionMechanism();

            for (int i = 0; i < 3; i++)
            {
                var advertiser = auctionHost.CreateAdvertiser();
                auctionHost.Advertisers.Add(advertiser);
                advertiser.Tactics = new KeywordAuction.Tactics.BreadthFirstTactics();
                advertiser.Strategies.Add(new Strategy.StrategyJump());
                advertiser.Strategies.Add(new Strategy.StrategyRaiseValue { Value = 5 });
                advertiser.Strategies.Add(new Strategy.StrategyDropValue { Value = 5 });
                
                advertiser.Strategies.Add(new StrategyRaiseAll { });

                advertiser.Strategies.Add(new StrategyDropAll { });

              advertiser.Strategies.Add(new StrategyHoldAll());
                advertiser.Name = string.Format("Player {0}", i);
            }

            var ctrs = new List<double>();
            ctrs.Add(0.6131);
            ctrs.Add(0.5111);
            var adspot = KeywordAuction.Utility.AdspotFactory.Create(auctionHost, 171, 2, ctrs);
            adspot.Name = "Adspot 0";
            auctionHost.Adspots.Add(adspot);
            var random = new Random();
            double value = 26;
            foreach (var spot in auctionHost.Adspots)
            {
                foreach (var advertiser in auctionHost.Advertisers)
                {
                    var bidding = AdvertiserBidding.CreateAdvertiserBidding(advertiser, spot);
                    bidding.ExpectedRevenue = value;// random.Next(30, 100);
                    if (value == 26)
                    {
                        value = 60;
                    }
                    else
                    {
                        value = 69;
                    }
                    advertiser.Biddings.Add(bidding);
                    spot.Bitting.Add(bidding);
                }
            }

            return auctionHost;
        }
    }


    public class AuctionFactoryForChapter5WithGFP : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var factory = new AuctionFactoryForChapter5WithGSP();
            var host= factory.Create();
            host.Name = "Chap5.ExtendStrategyWithGFP";
            host.AuctionMechanism = new GFPAuctionMechanism();
            return host;
        }
    }


    public class AuctionFactoryForChapter5WithLEF : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var factory = new AuctionFactoryForChapter5WithGSP();
            var host = factory.Create();

            host.Name = "Chap5.ExtendStrategyWithLEFGSP";
            host.AuctionMechanism = new LEFGSPAuctionMechanism();
            return host;
        }
    }

    public class AuctionFactoryForChapter5WithVCG : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var factory = new AuctionFactoryForChapter5WithGSP();
            var host = factory.Create();

            host.Name = "Chap5.ExtendStrategyWithVCG";
            host.AuctionMechanism = new VCGAuctionMechanism();
            return host;
        }
    }
}
